import 'package:flutter/material.dart';
import 'package:x3_base_package/x3_base_package.dart';
import 'package:x3_business_core/business_customer/less_components/business_customer_details_circle_progress.dart';
import 'package:x3_business_core/business_customer/less_components/business_customer_details_customer_dynamic.dart';
import 'package:x3_business_core/business_customer/less_components/business_customer_details_header.dart';
import 'package:x3_business_core/business_customer/less_components/business_customer_details_service.dart';
import 'package:x3_business_core/business_customer/less_components/business_customer_details_tags.dart';

class BusinessCustomerDetails extends StatefulWidget {

  static final String sName = 'DepotVipDetails';

  @override
  _BusinessCustomerDetailsState createState() => _BusinessCustomerDetailsState();

}

class _BusinessCustomerDetailsState extends State<BusinessCustomerDetails> {

  List<BaseTabConfig> _baseTabConfig = [];

  BaseTabBarPage _baseTabBarPage;

  /// 当前的会员信息是否有编辑过 如果有编辑过,则赋值为true 返回会刷新会员列表
  bool _isEdited = false;

  @override
  Widget build(BuildContext context) {
    dynamic arguments = BaseRouterUtil.getArguments(context);
    String vipId = BaseUtils.getKeyData(arguments, 'vipId').toString();
    _baseTabConfig = [
      BaseTabConfig(text: '会员动态', child: BusinessCustomerDetailsCustomerDynamic(vipId: vipId)),
      BaseTabConfig(text: '服务工具', child: BusinessCustomerDetailsService(vipId: vipId)),
      // BaseTabConfig(text: '推荐商品', child: BusinessCustomerDetailsRecommend(vipId: vipId)),
    ];
    _baseTabBarPage = BaseTabBarPage(_baseTabConfig);
    return BaseScaffoldComponent(
      title: '会员详情',
      child: BaseNestedScrollView(
        pinnedWidget: BaseNestedScrollPinned(child: _buildPinnedWidget()),
        headerWidget: _buildHeaderWidget(vipId),
        contentWidget: _baseTabBarPage.buildTabView(),
      ),
      willPopScope: _willPopScope,
    );
  }

  Future<bool> _willPopScope() {
    BaseRouterUtil.getInstance().pop( this._isEdited );
    return Future.value( false );
  }

  Widget _buildHeaderWidget(String vipId) {
    return Column(
      children: [
        BusinessCustomerDetailsHeader(vipId: vipId, editCallback: () => this._isEdited = true ),
        BusinessCustomerDetailsCircleProgress(vipId: vipId),
        BusinessCustomerDetailsTags(vipId: vipId),
        SizedBox(height: 6),
      ],
    );
  }

  Widget _buildPinnedWidget() {
    return BaseCardComponent(
      margin: EdgeInsets.symmetric(horizontal: 16, vertical: 0),
      padding: EdgeInsets.zero,
      child: Container(
        child: _baseTabBarPage.buildTabBar(context, isScrollable: false, color: Colors.transparent),
      ),
    );
  }

  @override
  void dispose() {
    _baseTabBarPage.dispose();
    super.dispose();
  }

}
